import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;

/**
 * @ClassName DataSourceConfig
 * @Description TODO
 * @Author 86181
 * @Date 2022/8/25 1:57
 * @Version 1.0
 **/
public class DataSourceConfig {

    //根据c3p0-config.xml初始化一个数据源,我们可以从数据源里面获取连接对象(此时已经自动加载了c3p0-config.xml配置文件)
    static ComboPooledDataSource dataSource = new ComboPooledDataSource();

    /**
     * 获取数据源的方法
     * @return
     */
    public static ComboPooledDataSource getDataSource() {
        return dataSource;
    }
    /**
     * 获取连接对象
     * @return
     * @throws Exception 7
     */
    public static Connection getConnection() throws Exception{
        return dataSource.getConnection();
    }
}
